from django.shortcuts import render, render_to_response, get_object_or_404
from django.http import HttpResponse, Http404

from .models import Article
# Create your views here.


def index(request):
    return HttpResponse('hello world')

def article_detail(request, article_id):
    article = get_object_or_404(Article, pk=article_id)
    context = {
        'article_obj': article,
    }
    return render_to_response('article_detail.html', context)
    # return render(request, 'article_detail.html', context)

    # return HttpResponse('文章Id: %s<h2>文章标题: %s</h2><p>文章内容: %s</p>' % (article.id, article.title, article.content))

def article_list(request):
    # articles = Article.objects.all()
    articles = Article.objects.filter(is_deleted=False)
    context = {}
    context['articles'] = articles
    return render_to_response('article_list.html', context)
